# -*- coding: utf-8 -*-
"""
@Time ： 2020/11/11 20:57
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：美团外卖小程序自动化录制
"""

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
import time

from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "3e5d55a"
caps["appPackage"] = "com.tencent.mm"
caps["appActivity"] = ".ui.LauncherUI"
caps["noReset"] = True
caps["unicodeKeyboard"] = True
caps["resetKeyboard"] = True
caps["automationName"] = "uiautomator1"
caps["ensureWebviewsHavePages"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(15)

driver.find_element_by_id('com.tencent.mm:id/f8y')
time.sleep(2)
TouchAction(driver).press(x=532, y=304).move_to(x=479, y=1665).release().perform()

time.sleep(1)
els1 = driver.find_elements_by_xpath("//*[@text='美团外卖']")
els1[0].click()

time.sleep(8)
els2 = driver.find_elements_by_xpath("//*[@text='美食']")
els2[0].click()
el1 = driver.find_element_by_id("chennel_search_input")
el1.click()
el2 = driver.find_element_by_id("search_input")
el2.send_keys("猪脚")
el3 = driver.find_element_by_id("search_button")
el3.click()

driver.quit()